package me.zfz.business.service;

import me.zfz.base.bean.SmartResponse;
import me.zfz.base.constant.IConstant;
import me.zfz.base.exception.DaoException;
import me.zfz.base.exception.ServiceException;
import me.zfz.base.helper.ObjectHelper;
import me.zfz.base.service.impl.MgrServiceImpl;
import me.zfz.business.bean.JobSearchParam;
import me.zfz.business.bean.TrainSearchParam;
import me.zfz.business.bean.entity.JobInfo;
import me.zfz.business.bean.entity.TrainInfo;
import me.zfz.business.dao.impl.JobInfoDao;
import me.zfz.business.dao.impl.TrainInfoDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author author
 */
@Service("jobService")
public class JobInfoService extends MgrServiceImpl<JobInfo> {

    @Autowired
    private JobInfoDao jobInfoDao;

    /**
     * 根据searchParam参数查询信息
     *
     * @param searchParam
     * @param start
     * @param rows
     * @return
     * @throws ServiceException
     */
    public SmartResponse<Object> findAllObj(JobSearchParam searchParam, int start, int rows) throws ServiceException {
        SmartResponse<Object> smartResp = new SmartResponse<Object>();
        smartResp.setResult(IConstant.OP_NOT_DATA_SUCCESS);
        smartResp.setMsg(IConstant.OP_NOT_DATA_SUCCESS_MSG);
        try {
            List<Object> objs = jobInfoDao.queryObjPage(searchParam, start, rows);
            if (null != objs && objs.size() > 0) {
                smartResp.setResult(IConstant.OP_SUCCESS);
                smartResp.setMsg(IConstant.OP_SUCCESS_MSG);
                objs = ObjectHelper.handleObjDate(objs);
                smartResp.setDatas(objs);
                long total = jobInfoDao.queryObjCount(searchParam);
                smartResp.setTotalNum(total);
                smartResp.setTotalPage(getTotalPage(total, rows));
            }
        } catch (DaoException e) {
            throw new ServiceException(e.getMessage(), e.getCause());
        } catch (Exception e) {
            throw new ServiceException(e.getCause());
        }
        return smartResp;
    }

    public JobInfoDao getDao() {
        return (JobInfoDao) super.getDao();
    }

}
